#include "Bullet.h"

Bullet::Bullet()
	: mActive(false) 
{
	
};

Bullet::~Bullet()
{

};

void Bullet::Load()
{
	mSprite.Load("bullet3.png");
}; // initialize

void Bullet::Unload()
{
	mSprite.Unload();
}; // terminate

void Bullet::Update(float deltaTime)
{
	if (mActive)
	{
		mPosition += mVelocity * deltaTime;
		
		// controls when bullets die
		const int kWinWidth = IniFile_GetInt("WinWidth", 800);
		const int kWinHeight = IniFile_GetInt("WinHeight", 600);

		const int kMaxColumns = 50;
		const int kMaxRows = 25;

		const int kThreshold = mSprite.GetWidth();
		if (mPosition.x < -kThreshold || mPosition.x > kWinWidth + kThreshold||
			mPosition.y < -kThreshold || mPosition.y > kWinHeight + kThreshold)
		{
			//Kill();
		}

	}
};

void Bullet::Render(const SVector2& viewOffset)
{
	if (mActive)
	{
		int width = mSprite.GetWidth();
		int height = mSprite.GetHeight();
		SVector2 renderPosition = mPosition - viewOffset; 
		mSprite.SetPosition(renderPosition);
		mSprite.Render();
	}
};

void Bullet::Fire(const SVector2& pos, const SVector2& vel)
{
	mPosition = pos;
	mVelocity = vel;
	mActive = true;
};

void Bullet::Kill()
{
	mActive = false;
}